package com.maykk.Demo02;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @ClassName: Demo02Test
 * @Description: TODO 测试静态封装的 JDBC 工具类
 * @Author: MaykkStar@163.com
 */
public class Demo02Test {
    public static void main(String[] args) throws SQLException {
        // 获取连接
        Connection conn = JdbcUtils.getConnection();
        // 获取执行 sql 语句的对象
        Statement st = conn.createStatement();

        // 准备 sql 语句
        String sql = "select `id`,`name`,`sex`,`age`,`score`,`tel` from `stu`";
        ResultSet rs = st.executeQuery(sql);

        // 处理结果
        showRes(rs);

        // 释放资源
        JdbcUtils.free(rs,st,conn);
    }

    private static void showRes(ResultSet rs) throws SQLException {
        while (rs.next()){
            System.out.printf(
                    "├————————————————————————————————————————————┥\n"+
                    "|%d\t|%3s\t|%s\t|%d\t|%4.1f\t|%s|\n"+
                    "├————————————————————————————————————————————┥\n",
                    rs.getInt("id"),
                    rs.getString("name"),
                    rs.getObject("sex"),
                    rs.getInt("age"),
                    rs.getFloat("score"),
                    rs.getString("tel")
            );
        }
    }
}
